<?xml version="1.0" encoding="UTF-8"?><Module>
<ModulePrefs title="好友对战 Friends Fight" description="选择一个好友，和Ta开始对战吧" author="齐文" author_email="hs1107033@gmail.com" height="500">
    <Require feature="dynamic-height"/>
    <Require feature="opensocial-0.7"/>
</ModulePrefs>
<Content type="html">
<![CDATA[
<html>
    <head>
        <title>Friends Fight</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <style type="text/css">
		.pk_title{
			text-align:center;
			font-size:20px;
		}
		.pk_title_comment{
			text-align:right;
			font-size:14px;
		}		
		#pk_layout{
			margin: 0px auto;
		}
		input {
			font : icon;
		}
		td {
			padding :0px;
			font-family : arial, helvetica, sans-serif;
			font-size : x-small;
		}
		a {color:#005EAC;}
		a:link, a:visited {color:#005EAC;text-decoration:none;}
		a:hover {color:#005EAC;text-decoration:underline;}
		a.dark {color:#333;}
		.navigation_b a:hover {
			text-decoration : underline;
		}
		a img {
			border : 0px;
			vertical-align : middle;
		}
		.navigation {
			background-image : url(http://www.phpxuexi.cn/OpenSocial/FriendsFight/images/fond_nav.jpg);
			height : 105px;
			padding-left : 14px;
			padding-right : 8px;
			vertical-align:top;
		}
		.navigation a {
			display : block;
			padding : 6px;
			background-image : url(http://www.phpxuexi.cn/OpenSocial/FriendsFight/images/fond_a.gif);
		}
		.navigation a:hover {
			background-image : url(http://www.phpxuexi.cn/OpenSocial/FriendsFight/images/fond_a_over.gif);
		}
		.navigation_b {
			background-image : url(http://www.phpxuexi.cn/OpenSocial/FriendsFight/images/nav_bas.jpg);
			width : 184px;
			height : 36px;
			vertical-align:top;
		}
		.navigation_b div {
			padding-left : 20px;
			padding-top : 6px;
		}
		.main {
			background-image : url(http://www.phpxuexi.cn/OpenSocial/FriendsFight/images/fond_main.jpg);
			width : 387px;
			height : 234px;
		}
		.main input {
			border : 0px;
			width : 240px;
			padding : 6px;
			background-color : transparent;
		}
		.valide a {
			display : block;
			width : 111px;
			height : 32px;
		}
		.hide {
			width : 0px;
			height: 0px;
		}
		.mot1 {
			background-image : url(http://www.phpxuexi.cn/OpenSocial/FriendsFight/images/form_mot1.jpg);
			padding-top : 23px;
			padding-left : 12px;
			padding-bottom: 2px;
		}
		.mot2 {
			background-image : url(http://www.phpxuexi.cn/OpenSocial/FriendsFight/images/form_mot2.jpg);
			padding-top : 2px;
			padding-left : 12px;
			padding-bottom: 13px;
		}
		.valide {
			background-image : url(http://www.phpxuexi.cn/OpenSocial/FriendsFight/images/form_valide.jpg);
			width : 276px;
			height : 37px;
			vertical-align : top;
			padding-top : 10px;
		}
		.valide a:hover {
			font-weight : bold;
		}
		.contenu {
			background-image : url(http://www.phpxuexi.cn/OpenSocial/FriendsFight/images/bord_contenu.jpg);
			width : 387px;
			height : 177px;
		}
		.contenu iframe {
			margin-left : 11px;
			width : 359px;
			height : 178px;
		}
		.adds {
			text-align : center;
			vertical-align:top;
		}
		.mozbot {
			position : relative;
			left : -10px;
			text-align : center;
			width : 250px;
			padding : 6px;
			border : 1px solid #CCCCCC;
			margin-top : 40px;
			border-left : 5px solid #DCDCDC;
			font-size : 9pt;
		}
		.mozbot a {
			color : #9ABB5E;
			font-weight : bold;
		}
		.mozbot a:hover {
			text-decoration : underline;
		}
		</style>
    </head>
    <body style="color:#005EAC; background-color:background: rgb(244, 248, 255);">
    <div id="pk_layout">
        <table align="center" width="582px">
            <tr>
                <td colspan="2">
                    <div style="text-align:center; font-size:14px; width:100%; color:#005EAC; padding: 5 5 5 5;">
                        Friends Fight 好友对战
                    </div>
                    <div style="text-align:center; font-size:12px; width:100%; color:#005EAC; padding-right:10px; padding-bottom:5px; ">
                        Choose a friend and make a fight.. 选一个好友，开始你们的对战吧。
                    </div>
                </td>
            </tr>
            <tr>
                <td width="200" id="pk_left_td" style="vertical-align:top; font-size:14px; overflow:auto;">
                    <div id="pk_left_owner" align="center" style="padding: 5 5 5 5;">
                        Loading...加载中...
                    </div>
                    <div id="pk_left" style="overflow:auto; height:413px; line-height:14pt; letter-spacing:0.2em;">
                        &nbsp;
                    </div>
                </td>
                <td width="387" style="vertical-align:top;">
                    <div style="padding-top:15px;">
                        <table cellspacing="0" align="center" width="387px">
                            <tr>
                                <td>
                                    <img src="http://www.phpxuexi.cn/OpenSocial/FriendsFight/images/fond_top.jpg" alt="versus" />
                                </td>
                            </tr>
                            <tr>
                                <td class='contenu'>
                                    <iframe frameborder="0" src="http://www.phpxuexi.cn/OpenSocial/FriendsFight/noquery.php" name="content" id="content">
                                    </iframe>
                                </td>
                            </tr>
                            <tr>
                                <td class='main'>
                                    <table cellspacing="0" align="center">
                                        <tr>
                                            <td class='mot1'>
                                                <input onKeyPress="if(event.keyCode == 13) {goPK();}" type="text" value="Name1" name="word1" id="word1" />
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <img src="http://www.phpxuexi.cn/OpenSocial/FriendsFight/images/form_versus.jpg" alt="versus" />
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class='mot2'>
                                                <input onKeyPress="if(event.keyCode == 13) {goPK();}" type="text" value="Name2" name="word2" id="word2" />
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class='valide' align="center">
                                                <div onMouseOut="chgCursorDefault();" onMouseOver="chgCursorHand();" onClick="goPK();">
                                                    Make a fight
                                                </div>
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                        </table>
                    </div>
                </td>
            </tr>
        </table>
    </div>
    </div>
</script>
<script type="text/javascript">
    Date.prototype.format = function(format){
        var o = {
            "Y+": this.getYear(), 
            "M+": this.getMonth() + 1, 
            "d+": this.getDate(),
            "h+": this.getHours(),
            "m+": this.getMinutes(),
            "s+": this.getSeconds(),
            "q+": Math.floor((this.getMonth() + 3) / 3),
            "S": this.getMilliseconds()
        };
        if (/(y+)/.test(format)) {
            format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
		}
        for (var k in o) {
            if (new RegExp("(" + k + ")").test(format)) {
                format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
			}	
		}
        return format;
    };
    
    var clicked_friend_name;
    var clicked_friend_id;
    function goPK(){
        var contentSrc = "http://www.phpxuexi.cn/OpenSocial/FriendsFight/query.php?word1=";
        //var contentSrc = "http://localhost/os/FriendsFight/query.php?word1=";
        contentSrc += document.getElementById("word1").value;
        contentSrc += "&word2=" + document.getElementById("word2").value;
        document.getElementById('content').src = contentSrc;
        if (clicked_friend_name == document.getElementById('word2').value) {
            PostActivity();
        }
    }
    
    function chgCursorHand(){
        document.body.style.cursor = "hand";
    }
    
    function chgCursorDefault(){
        document.body.style.cursor = "default";
    }
    
    function getRandomFirend(){
        var randomFriendIndex = Math.random();
        var randomFriendIndex = Math.round(randomFriendIndex * (friends.length - 1));
        document.getElementById("word2").value = friends[randomFriendIndex].getDisplayName();
    }
    
    function clickFriend(i){
        document.getElementById("word2").value = friends[i].getDisplayName();
        clicked_friend_name = friends[i].getDisplayName();
        clicked_friend_id = friends[i].getField(opensocial.Person.Field.ID);
    }
    
    var friends = Array(); /* Request for friend information. */
    function getData(){
        var req = opensocial.newDataRequest();
        var params = {};
        params[opensocial.DataRequest.PeopleRequestFields.MAX] = 1000;
        params[opensocial.DataRequest.PeopleRequestFields.PROFILE_DETAILS] = [opensocial.Person.Field.ABOUT_ME, opensocial.Person.Field.STATUS, opensocial.Person.Field.PROFILE_URL, opensocial.Person.Field.NAME, opensocial.Person.Field.THUMBNAIL_URL];
        
        req.add(req.newFetchPersonRequest(opensocial.DataRequest.PersonId.OWNER, params), 'viewer');
        req.add(req.newFetchPeopleRequest('VIEWER_FRIENDS', params), 'viewerFriends');
        
        req.send(onLoadFriends);
    };
    
    var appURL = "http://apps.xiaonei.com/pkpkpkpk";
    function PostActivity(){
        var params = {};
        params[opensocial.Activity.Field.TITLE] = ('<a href=http://xiaonei.com/profile.do?id=' + id_owner + '>' + name_owner + '</a>和<a href="http://xiaonei.com/profile.do?id=' + clicked_friend_id + '">' + clicked_friend_name + '</a>在“<a href="' + appURL + '">好友对战</a>”中玩了一把！赶紧来和' + name_owner + '<a href="' + appURL + '">对战</a>一下吧！' + (new Date().format("yyyy-MM-dd hh:mm:ss")));
        var activity = opensocial.newActivity(params);
        opensocial.requestCreateActivity(activity, opensocial.CreateActivityPriority.HIGH);
    }
    
    var friendsIndex = 0;
    var name_owner;
    var id_owner;
    function onLoadFriends(data){
        var viewer = data.get('viewer').getData();
        var uid = viewer.getField(opensocial.Person.Field.ID);
        id_owner = uid;
        var img = viewer.getField(opensocial.Person.Field.THUMBNAIL_URL);
        var name = viewer.getDisplayName();
        var viewerFriends = data.get('viewerFriends').getData();
        var html_owner = name + '的好友们';
        name_owner = name;
        var html = '';
        html += '<table width="150" border="0" cellspacing="5" cellpadding="0">';
        viewerFriends.each(function(person){
            friends[friendsIndex] = person;
            var fname = person.getDisplayName();
            var fimg = person.getField(opensocial.Person.Field.THUMBNAIL_URL);
            if (friendsIndex % 3 == 0) {
                if (friendsIndex != 0) {
                    html += '</tr>';
                }
                html += '<tr>';
            }
            html += '<td onclick="clickFriend(' + friendsIndex + ')"  ';
            html += 'onMouseOut="chgCursorDefault()" onMouseOver="chgCursorHand()" >';
            html += '<div style="overflow:hidden; width:50px; height:50px;"><img src="' + fimg + '" title="' + fname + '" /></img></div></td>';
            friendsIndex++;
        });
        var blank_div = friendsIndex % 3;
        for (var ti = 1; ti < blank_div; ti++) {
            html += '<td>&nbsp;</td>';
        }
        html += '</tr></table>';
        getRandomFirend();
        document.getElementById('pk_left_owner').innerHTML = html_owner;
        document.getElementById("word1").value = viewer.getDisplayName();
        document.getElementById('pk_left').innerHTML = html;
    };
    gadgets.util.registerOnLoadHandler(getData);
</script>
</body>
</html>
]]>
  </Content>
</Module>